<template>
  <div class="banner">
    <swiper ref="mySwiper"  :options="swiperOption" class="swiper">
      <swiper-slide
        v-for="item in banner"
        :key="item.imageUrl"
        :alt="item.typeTitle"
        class="slide"
      >
        <el-image
          :src="item.imageUrl"
          class="banner-img"
          :alt="item.typeTitle"
          @click="pathHandler(item)"
        >
          <div slot="placeholder" class="image-slot">
        <i class="el-icon-picture-outline"></i>
      </div>
        </el-image>
      </swiper-slide>
      <div class="swiper-pagination" slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
export default {
  name: "banner",
  data() {
    return {
      banner: [],
      swiper:null,
      swiperOption: {
        //配置对象
        slidesPerView: 3, //每行显示几个
        spaceBetween: 45, //间距
        slidesPerGroup: 3, //每三个为一列
        loop: true, //无缝轮播
        loopFillGroupWithBlank: true,
        pagination: {
          //分页器
          el: ".swiper-pagination",
          clickable: true, //点击切换轮播图
        },
      },
    };
  },
  created() {
    this.getBanner();
  },
   computed: {
    },
    mounted() {
      this.swiper = this.$refs.mySwiper.$swiper;
      this.swiper.slideTo(3, 1000, false)
    },
  methods: {
    async getBanner() {
      const res = await this.$api.getBanner();
      // console.log(res);
      this.banner = res.banners;
    },
    pathHandler(item) {
      console.log(item);
      switch(item.targetType){
        case 3000:   //外部链接
          window.open(item.url);
          break;
        case 1:     //单曲
          this.$router.push({name:'Song',query:{id:item.targetId}})
          break;
        case 10:   //专辑
          this.$router.push({name:'Album',query:{id:item.targetId}})
          break;
        case 1000: //歌单
        this.$router.push({name:'Songsheet',query:{id:item.targetId}})
          break;
        case 1004: //mv
        this.$router.push({name:'Mv',query:{id:item.targetId}})
          break;
      }
    },
  },
};
</script>

<style lang="less" scoped>
.banner {
  margin-top: 110px;
  width: 100%;
  height: 230px;
  .swiper {
    width: 1200px;
    height: 230px;
    padding: 0 40px;
    position: relative;
    font-size: 0;
    .swiper-slide,
    .el-image {
      height: 140px;
      width: 120px;
      border-radius: 4px;
    }
    .image-slot{
     height: 120px;
      border: 1px solid #ccc;
      border-radius: 4px;
      font-size: 28px;
      color:#ccc;
     display: flex;
     justify-content: center;
     align-items: center;
    }
    .banner-img {
        width: 100%;
        height: 100%;
        cursor: pointer;
    }
    /deep/.swiper-pagination {
      position: absolute;
      height: 20px;
      left: 50%;
      top: 80%;
      transform: translate(-50%, -80%);
      width: 200px;
      bottom: 10px;
      z-index: 10;
      span {
        margin: 5px;
        width: 10px;
        height: 10px;
      }
    }
  }
}
</style>